package com.dlc.demo.daiqianma.model;

import android.util.Log;

import com.dlc.demo.daiqianma.entity.ApplyForLoanSubmitStateEntity;
import com.dlc.demo.daiqianma.entity.UserEntity;
import com.dlc.demo.daiqianma.rservice.ApplyForLoanService;
import com.dlc.demo.daiqianma.rservice.UserService;

import retrofit2.Call;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ApplyForLoanModel {
    /**
     * 获取申请信息状态
     * @param token 用户token
     * @param callback 回调
     */
    public static  void getApplyForLoanState(String token,final Callback<ApplyForLoanSubmitStateEntity> callback){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(API.BASE_URL)//基础URL
                .addConverterFactory(GsonConverterFactory.create())//设置 Json 转换器
                .build();
        ApplyForLoanService applyForLoanService= retrofit.create(ApplyForLoanService.class);
        Call<ApplyForLoanSubmitStateEntity> call = applyForLoanService.getApplyForLoanState(token);
        call.enqueue(new retrofit2.Callback<ApplyForLoanSubmitStateEntity>() {
            @Override
            public void onResponse(Call<ApplyForLoanSubmitStateEntity> call, Response<ApplyForLoanSubmitStateEntity> response) {
                //测试数据返回
                ApplyForLoanSubmitStateEntity applyForLoanSubmitStateEntity = response.body();
                callback.onSuccess(applyForLoanSubmitStateEntity);
                callback.onComplete();
            }

            @Override
            public void onFailure(Call<ApplyForLoanSubmitStateEntity> call, Throwable t) {
                Log.e("TAG", "Throwable : " + t);
                callback.onFailure(t.toString());
                callback.onComplete();
            }
        });
    }
}
